package com.heima.admin.controller.v1;

import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.admin.service.AdChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")

public class ChannelController implements AdChannelControllerApi {
    @Autowired
    private AdChannelService adChannelService;

    /**
     * 查询所有的频道
     *
     * @return
     */
    @Override
    @PostMapping("/findAll")
    public ResponseResult findAllChannel() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }

    @Override
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {

        return adChannelService.findByNameAndPage(dto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult addChannel(@RequestBody  AdChannel adChannel) {
        return adChannelService.add(adChannel);
    }

    @Override
    @PostMapping("/update")
    public ResponseResult editChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.editChannel(adChannel);
    }

    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id) {
        return adChannelService.deleteChannel(id);
    }
}
